package gsd.gaudi.server;

import java.lang.reflect.Method;
import java.util.Arrays;


public class Launcher {

	private String mainclass;
	private String[] args;
	
	public Launcher(String mc, String[] args){
		this.mainclass = mc;
		int i = 0;
		for(String s : args){
			if(s.equals(mc))
				break;
			i++;
		}
		this.args = Arrays.copyOfRange(args, i, args.length);
	}
	
	public void launch(){
		try 
		{
			Class<?> c = Class.forName(mainclass);
			Class[] argTypes = new Class[] { String[].class };
			Method main = c.getDeclaredMethod("main", argTypes);
			String[] mainArgs = Arrays.copyOfRange(this.args, 0, args.length);
			main.invoke(null, (Object)mainArgs);
		} catch (Exception x) {
			x.printStackTrace();
		}
	}
	
	
}
